package svg

import (
	"gosvg/dom"
)

type RectElement struct {
	*dom.Element
}

func Rect() *RectElement {
	return &RectElement{Element: dom.MakeElementNs("rect", SvgNamespace)}
}

//X sets the x-axis coordinate of the side of the rectangle which has the smaller 
//x-axis coordinate value in the current user coordinate system. 
//If the attribute is not specified, the effect is as if a value 
//of "0" were specified.
func (r *RectElement) X(x float64) {
	r.Element.SetAttribute("x", fVal(x))
}

//Y sets the y-axis coordinate of the side of the rectangle which has the smaller 
//y-axis coordinate value in the current user coordinate system. 
//If the attribute is not specified, the effect is as if a value 
//of "0" were specified.
func (r *RectElement) Y(y float64) {
	r.Element.SetAttribute("y", fVal(y))
}

//Width sets the width of the rectangle.
//A negative value is an error (see http://www.w3.org/TR/SVG11/implnote.html#ErrorProcessing). 
//A value of zero disables rendering of the element.
func (r *RectElement) Width(width float64) {
	r.Element.SetAttribute("width", fVal(width))
}

//Height sets the height of the rectangle.
//A negative value is an error (see http://www.w3.org/TR/SVG11/implnote.html#ErrorProcessing). 
//A value of zero disables rendering of the element.
func (r *RectElement) Height(height float64) {
	r.Element.SetAttribute("height", fVal(height))
}

//Rx sets the x-axis radius of the ellipse 
//used to round off the corners of the rectangle.
//A negative value is an error (see Error processing).
func (r *RectElement) Rx(rx float64) {
	r.Element.SetAttribute("rx", fVal(rx))
}

//Ry sets the y-axis radius of the ellipse 
//used to round off the corners of the rectangle.
//A negative value is an error (see Error processing).
func (r *RectElement) Ry(ry float64) {
	r.Element.SetAttribute("ry", fVal(ry))
}

type CircleElement struct {
	*dom.Element
}

func Circle() *CircleElement {
	return &CircleElement{Element: dom.MakeElementNs("circle", SvgNamespace)}
}

//X sets the x-axis coordinate of the center of the circle.
//If the attribute is not specified, the effect is 
//as if a value of "0" were specified.
func (r *CircleElement) X(cx float64) {
	r.Element.SetAttribute("cx", fVal(cx))
}

//Y sets the y-axis coordinate of the center of the circle.
//If the attribute is not specified, the effect is 
//as if a value of "0" were specified.
func (r *CircleElement) Y(cy float64) {
	r.Element.SetAttribute("cy", fVal(cy))
}

//Radius sets the radius of the circle.
func (r *CircleElement) Radius(radius float64) {
	r.Element.SetAttribute("r", fVal(radius))
}

type EllipseElement struct {
	*dom.Element
}

func Ellipse() *EllipseElement {
	return &EllipseElement{Element: dom.MakeElementNs("ellipse", SvgNamespace)}
}

//X sets the x-axis coordinate of the center of the ellipse.
//If the attribute is not specified, the effect is 
//as if a value of "0" were specified.
func (r *EllipseElement) X(cx float64) {
	r.Element.SetAttribute("cx", fVal(cx))
}

//Y sets the y-axis coordinate of the center of the ellipse.
//If the attribute is not specified, the effect is 
//as if a value of "0" were specified.
func (r *EllipseElement) Y(cy float64) {
	r.Element.SetAttribute("cy", fVal(cy))
}

//RadiusX sets the x-axis radius of the ellipse.
func (r *EllipseElement) RadiusX(radius float64) {
	r.Element.SetAttribute("rx", fVal(radius))
}

//RadiusY sets the y-axis radius of the ellipse.
func (r *EllipseElement) RadiusY(radius float64) {
	r.Element.SetAttribute("ry", fVal(radius))
}

//Radius sets the radii of the ellipse.
func (r *EllipseElement) Radius(xradius, yradius float64) {
	r.RadiusX(xradius)
	r.RadiusY(yradius)
}

type LineElement struct {
	*dom.Element
}

func Line() *LineElement {
	return &LineElement{Element: dom.MakeElementNs("line", SvgNamespace)}
}

//X1 sets the x-axis coordinate of the start of the line.
func (r *LineElement) X1(x1 float64) {
	r.Element.SetAttribute("x1", fVal(x1))
}

//Y1 sets the The y-axis coordinate of the start of the line.
func (r *LineElement) Y1(y1 float64) {
	r.Element.SetAttribute("y1", fVal(y1))
}

//X2 sets the x-axis coordinate of the end of the line.
func (r *LineElement) X2(x2 float64) {
	r.Element.SetAttribute("x2", fVal(x2))
}

//Y2 sets the y-axis coordinate of the end of the line.
func (r *LineElement) Y2(y2 float64) {
	r.Element.SetAttribute("y2", fVal(y2))
}

type PolyLineElement struct {
	*dom.Element
}

func PolyLine() *PolyLineElement {
	return &PolyLineElement{Element: dom.MakeElementNs("polyline", SvgNamespace)}
}

func (p *PolyLineElement) Point(x, y float64) *PolyLineElement {
	p.Element.AddToAttribute("points", coords(x, y))
	return p
}

type PolygonElement struct {
	*dom.Element
}

func Polygon() *PolygonElement {
	return &PolygonElement{Element: dom.MakeElementNs("polygon", SvgNamespace)}
}

func (p *PolygonElement) Point(x, y float64) *PolygonElement {
	p.Element.AddToAttribute("points", coords(x, y))
	return p
}
